/**
 * 
 */
package com.ubo.transform.java;

import java.util.Enumeration;
import java.util.Stack;


/**
 * @author saludegu
 * 
 */
public abstract class AJavaVisitor<T> implements IJavaVisitor<T> {

	/**
	 * Stack de valeurs.
	 */
	private Stack<T> mStack;

	/**
	 * 
	 * Constructor
	 * 
	 */
	public AJavaVisitor() {
		mStack = new Stack<T>();
	}

	/**
	 * Ajout à la pile.
	 */
	protected void addToStack(T elem) {
		mStack.push(elem);
	}

	/**
	 * Getter du sommet de la pile.
	 * 
	 * @return
	 */
	protected T getFromStack() {
		return mStack.pop();
	}

	/**
	 * Vide la pile et renvoie toute les valeurs.
	 * 
	 * @return
	 */
	protected Enumeration<T> clearStack() {
		Enumeration<T> elts = mStack.elements();
		mStack.clear();
		return elts;
	}

	/**
	 * @see com.ubo.transform.java.IJavaVisitor#getValue()
	 */
	@Override
	public T getValue() {
		return mStack.pop();
	}

	/**
	 * 
	 * @return
	 */
	public T looKValue() {
		return mStack.peek();
	}
}
